<!--vue模板-->
<template>
  <el-dialog
    :model-value="visible"
    title="新增用户"
    width="600"
    :close-on-click-modal="false"
    @close="cls"
  >
    <el-form :model="user" label-width="100px" style="max-width: 600px">
      <el-form-item label="用户名">
        <el-input v-model="user.username" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="user.password" type="password" show-password />
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="user.name" />
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="user.gender">
          <el-radio :value="1" size="large">男</el-radio>
          <el-radio :value="2" size="large">女</el-radio>
          <el-radio :value="3" size="large">保密</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="user.mobile" />
      </el-form-item>
    </el-form>

    <div style="text-align: right">
      <el-button type="primary" @click="save">保存</el-button>
      <el-button type="info" @click="cls">取消</el-button>
    </div>
  </el-dialog>
</template>

<!--vue 组件选项定义-->
<script setup>
import { ref } from "vue";
import { ElMessage } from "element-plus";
//响应式对象
const user = ref({
  username: "",
  password: "",
  mobile: "",
  gender: 3,
  name: ""
});
//定义属性
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
});
//声明事件
const emits = defineEmits(["close"]);

//方法
function cls() {
  //通知父组件  我要关闭了
  emits("close");
}

//保存
function save() {
  console.log("user>>>", user.value);
  ElMessage({
    message: "保存成功",
    type: "success"
  });
  cls();
}
</script>

<!--vue样式 scoped当前样式只适用于当前组件-->
<style scoped></style>
